Wanted to know if anyone would be able to help me out in creating a script that will allow me to delete multiple attributes in a project. I have multiple folders and modules in a project that have attributes that are no longer used and need to delete them but don't want to have to go through each module and delete the attribute. Would be helpful if I can just select the project and have a script with all the attribute names in there and run it to delete them from all modules in the project. Currently all I could come up with is a script that deletes one attribute from one module only. |
Re: Delete Multiple Attributes in Project
Did not try to run this code, but it may get you going.
void DeleteAttributes(Module mod, Skip skpAttrNames)
{
string NameAttr,
NameMod = name(mod)
for NameAttr in mod do
{ ad = find(mod, NameAttr)
print NameMod "\t" NameAttr "\t"
if (null ad) print "No such attr\n"
else
{ ErrMess = delete(mod, ad)
if (!null ErrMess) "XX Error Deleting: " ErrMess
else print name(mod) "Deleted OK\n"
}
} // end for attrs to delete
} // end DeleteAttributes(mod)
void DeleteAttributes(Project prj, Skip skpAttrNames)
{
Item itm
Module mod
for itm in prj do
{ if (isDeleted(itm)) continue
if (type(itm) != "Formal") continue
mod = edit(fullName(itm), false, true, true) // Edit, invisible, silent, standard view
if (null mod or !isEdit(mod)) print name(itm) "\t\tCannot open Edit\n"
else(DeleteAttributes(mod, skpAttrNames)
save(mod)
close(mod)
} // end for all items in the Project
}
// ========= MAIN =========
Skip skpAttrNames = createString // KEY and DATA both 'string' Name of attr to delete
put(skpAttrNames, "Name1", "Name1")
put(skpAttrNames, "Name2", "Name2")
DeleteAttributes(current Project, skpAttrNames)
delete(skpAttrNames)
|
Re: Delete Multiple Attributes in Project llandale - Wed Apr 14 11:52:05 EDT 2010
Did not try to run this code, but it may get you going.
void DeleteAttributes(Module mod, Skip skpAttrNames)
{
string NameAttr,
NameMod = name(mod)
for NameAttr in mod do
{ ad = find(mod, NameAttr)
print NameMod "\t" NameAttr "\t"
if (null ad) print "No such attr\n"
else
{ ErrMess = delete(mod, ad)
if (!null ErrMess) "XX Error Deleting: " ErrMess
else print name(mod) "Deleted OK\n"
}
} // end for attrs to delete
} // end DeleteAttributes(mod)
void DeleteAttributes(Project prj, Skip skpAttrNames)
{
Item itm
Module mod
for itm in prj do
{ if (isDeleted(itm)) continue
if (type(itm) != "Formal") continue
mod = edit(fullName(itm), false, true, true) // Edit, invisible, silent, standard view
if (null mod or !isEdit(mod)) print name(itm) "\t\tCannot open Edit\n"
else(DeleteAttributes(mod, skpAttrNames)
save(mod)
close(mod)
} // end for all items in the Project
}
// ========= MAIN =========
Skip skpAttrNames = createString // KEY and DATA both 'string' Name of attr to delete
put(skpAttrNames, "Name1", "Name1")
put(skpAttrNames, "Name2", "Name2")
DeleteAttributes(current Project, skpAttrNames)
delete(skpAttrNames)
Thanks for your quick response. Ran into a couple of errors when I ran the script you provided on the forums. Here are the DXL errors I got: -E- DXL: <Line:10> incorrect arguments for function (delete) -E- DXL: <Line:11> incorrect arguments for (if) -E- DXL: <Line:11> incorrectly concatenated tokens -E- DXL: <Line:31> syntax error -I- DXL: all done with 4 errors and 0 warnings Here is your script with my attributes inserted: void DeleteAttributes(Module mod, Skip skpAttrNames) { string NameAttr, NameMod = name(mod) for NameAttr in mod do { ad = find(mod, NameAttr) print NameMod "\t" NameAttr "\t" if (null ad) print "No such attr\n" else { ErrMess = delete(mod, ad) if (!null ErrMess) "XX Error Deleting: " ErrMess else print name(mod) "Deleted OK\n" } } // end for attrs to delete } // end DeleteAttributes(mod) void DeleteAttributes(Project prj, Skip skpAttrNames) { Item itm Module mod for itm in prj do { if (isDeleted(itm)) continue if (type(itm) != "Formal") continue mod = edit(fullName(itm), false, true, true) // Edit, invisible, silent, standard view if (null mod or !isEdit(mod)) print name(itm) "\t\tCannot open Edit\n" else(DeleteAttributes(mod, skpAttrNames) save(mod) close(mod) } // end for all items in the Project } // ========= MAIN ========= Skip skpAttrNames = createString // KEY and DATA both 'string' Name of attr to delete put(skpAttrNames, "Exported", "Exported") put(skpAttrNames, "Feasible", "Feasible") DeleteAttributes(current Project, skpAttrNames) delete(skpAttrNames) Any help with the errors would be appreciated. Regards Vikesh |
Re: Delete Multiple Attributes in Project vppatel - Wed Apr 14 13:07:53 EDT 2010 Looks like I'm missing a "AttrDef ad" statement in the first function. And a "string ErrMess" You should turn auto-declare off, you get better error messages that way.
|
Re: Delete Multiple Attributes in Project llandale - Wed Apr 14 16:04:38 EDT 2010
Turned off auto-declare and this is what I get -E- DXL: <Line:6> incorrect arguments for (=) -E- DXL: <Line:6> undeclared variable (ad) -E- DXL: <Line:8> incorrect arguments for function (null) -E- DXL: <Line:10> incorrect arguments for function (delete) -E- DXL: <Line:10> undeclared variable (ErrMess) -E- DXL: <Line:11> incorrect argument for (!) -E- DXL: <Line:11> incorrect arguments for (if) -E- DXL: <Line:11> incorrect arguments for function (null) -E- DXL: <Line:8> incorrect arguments for (if) -E- DXL: <Line:31> syntax error too many messages -- suspending error reporting-I- DXL: all done with 10 errors and 0 warnings |
Re: Delete Multiple Attributes in Project vppatel - Thu Apr 15 09:56:04 EDT 2010 You should be able to interpret "-E- DXL: <Line:6> undeclared variable (ad)" as a need to declare "ad". If you are completely inexperienced with DXL then perhaps you should not be writing scripts that make ANY changes to the database, until you get some reasonable experience with the language and have some scripts that look around and display inforamtion.
|